package com.jp.knowledge.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.JsonObject;
import com.jp.knowledge.adapter.JobKnowledgeDetailAdapter;
import com.jp.knowledge.adapter.PositonKnowledgeAdapter;
import com.jp.knowledge.http.HttpHelper;
import com.jp.knowledge.view.JpDiver;
import com.jp.knowledge.view.SwipeItemLayout;

import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 * Created by 528787067@qq.com on 2017/7/13.
 */

public class JobKnowledgeDetailFragment extends ProductEvluationBaseFragment {

	public static JobKnowledgeDetailFragment newInstance(int type, String id){
		JobKnowledgeDetailFragment fragment = new JobKnowledgeDetailFragment();
		Bundle bundle = new Bundle();
		bundle.putInt("type", type);
		bundle.putString("id", id);
		fragment.setArguments(bundle);
		return fragment;
	}

	private int page;
	private String id;

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		id = getArguments().getString("id");
		cachePath = mContext.getCacheDir().getPath() + "/skill_detail_data_" + id + type + ".data";
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		adapter = new JobKnowledgeDetailAdapter(mContext, headLineDatas);
		refreshContent.setAdapter(adapter);
		if(application.getUserData() != null && application.getUserData().getPlatformAdmin() == 1)
			refreshContent.addOnItemTouchListener(new SwipeItemLayout.OnSwipeItemTouchListener(mContext));
		((JobKnowledgeDetailAdapter)adapter).setItemClickEventListener(new JobKnowledgeDetailAdapter.ItemClickEventListener() {
			@Override
			public void onItemClick(int position) {
				JobKnowledgeDetailFragment.this.onItemClick(null, position);
			}
			@Override
			public void onCancelClick(int position) {
				JsonObject param = new JsonObject();
				param.addProperty("choice", 0);
				param.addProperty("infoId", headLineDatas.get(position).getId());
				param.addProperty("state", 0);
				HttpHelper.getInstance(mContext).headlinesUpdateByAdmin(param, 0x01, null);
				headLineDatas.remove(position);
				adapter.notifyItemRemoved(position);
			}
		});
		return contentView;
	}

	@Override
	protected void getData(int mode) {
		if(mode == REFRESH_CODE)
			page = 1;
		else
			++page;
		JsonObject param = new JsonObject();
		param.addProperty("type", type);
		param.addProperty("page", page);
		param.addProperty("navTypeId", id);
		HttpHelper.getInstance(mContext).skillDetail(param, mode, this);
	}
}
